/*
 * @Author: zhousg
 * @Date: 2020-11-06 17:20:50
 * @Last Modified by: zhousg
 * @Last Modified time: 2021-01-04 12:16:02
 */

export const collectMixin = {
  data () {
    return {
      loading: false,
      list: [],
      total: 0,
      reqParams: {
        page: 1,
        pageSize: 12
      }
    }
  },
  created () {
    this.getList()
  },
  methods: {
    async getList () {
      this.loading = true
      await this.$sleep(500)
      const { data } = await this.$http.get('/member/collect', { params: this.reqParams })
      this.list = data.result.items
      this.total = data.result.counts
      this.loading = false
    },
    changePage (newPage) {
      this.reqParams.page = newPage
      this.getList()
    },
    del (id) {
      this.$confirm({ title: '温馨提示', text: '您确认取消收藏吗？' }).then(async (valid) => {
        if (valid) {
          await this.$http({
            method: 'delete',
            url: 'member/colletct/batch',
            data: {
              ids: [id],
              type: this.reqParams.collectType
            }
          })
          this.getList()
        }
      })
    }
  }
}
